package net.melon.sso.inst.bridge.provider;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import net.esj.auth.pojo.CoreAuthFunc;
import net.esj.basic.dao.querybuilder.QueryBuilder;
import net.esj.basic.service.DefaultService;
import net.esj.basic.service.provider.UserRuleProvider;
import net.melon.sso.pojo.Member;
import net.melon.sso.provider.MemberAuthProvider;

import org.springframework.stereotype.Service;

@Service
public class AutomatMemberAuthProvider implements MemberAuthProvider {

	@Resource
	private DefaultService defaultService;
	
	@Override
	public Collection<CoreAuthFunc> authFunctions(Member m) {
		Set<CoreAuthFunc> allFuncs ;
		QueryBuilder<CoreAuthFunc> qb = defaultService.createQueryBuilder(CoreAuthFunc.class);
		qb.eq("model.id", UserRuleProvider.getUserRule(Member.class).getAuthModel()).eq("disabled", false).OrderByAsc("sort");
		List<CoreAuthFunc> list = defaultService.queryListByQueryBuilder(qb);
		allFuncs = new LinkedHashSet<CoreAuthFunc>(list);
		return allFuncs;
	}

}
